package com.webserver.core;

import com.webserver.http.HttpContext;
import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 用于处理请求
 */
public class DispatcherServlet {
    public void service(HttpRequest request, HttpResponse response){
        String path =request.getUri();
        File file =new File("./webapps"+path);
        String line;
        if (file.isFile() && file.exists()){
            //资源存在
            response.setEntity(file);

        }else{
            //资源不存在
            response.setStatusCode(404);
            response.setStatusReason("NotFound");
            file =new File("./webapps/root/404.html");
            response.setEntity(file);
        }
        response.addHeader("Server","WebServer");
    }
}
